import { userOperationList, editUserOperationList } from '@/api/sys/user'
export default {
  data() {
    return {
      // RFQ全部公共字段
      cellIsShow: {
        IsItemNo: true,
        IsDpPrice: true,
        IsPartNumber: true,
        IsPartName: true,
        IsQty: true,
        IsSize: true,
        IsMaterialDetail: true,
        IsIdProcess: true,
        IsOwner: true,
        IsVendor1: true,
        IsVendor2: true,
        IsVendor3: true,
        IsVendor4: true,
        IsVendor5: true,
        IsCategory: true,
        IsCommodity: true,
        IsGcmOwner: true,
        IsRdFunction: true,
        IsGcmFunction: true,
        IsToolingCave: true,
        IsWeight: true,
        IsCost: true,
        IsSolution: true,
        IsTrackingOption: true
      }
    }
  },
  created() {
    this.getUserOperationList()
  },
  computed: {
    // 混入查找gcmOwner方法 减少代码量
    gcmOwnerById() {
      return gcmOwner => {
        if (gcmOwner && gcmOwner.length) {
          const newVal = []
          for (const val of gcmOwner) {
            newVal.push(this.$store.getters['user/getUserNameById'](val))
          }
          return newVal.join('|')
        } else {
          return ''
        }
      }
    }
  },
  methods: {
    // 获取当前表格当前用户的操作习惯
    async getUserOperationList() {
      try {
        const { data: res } = await userOperationList({ pageId: this.pageId })
        if (res && res.jsonObjectOperation) {
          // this.cellIsShow = res.jsonObjectOperation
          // 深拷贝
          const data = res.jsonObjectOperation
          this.cellIsShow = JSON.parse(JSON.stringify(data))
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 保存设置
    async saveOperationData(data) {
      try {
        await editUserOperationList({
          pageId: this.pageId,
          operationValue: JSON.stringify(data)
        })
        this.getUserOperationList()

        this.setDialogVisible = false
      } catch (error) {
        console.log(error)
      }
    }
  }
}
